using System;
using System.Collections.Generic;
using System.Text;

using KLATencor.CommonApp.Infrastructure.StateMachine;

using Syncfusion.Windows.Forms.Diagram.Controls;

using System.Windows.Forms;

using StateMachine_Graphical_Editor.Forms;

namespace StateMachine_Graphical_Editor.Graphics_Rendering
{
    /// <summary>
    /// Factory to create an initializer that will render the state machine elements within the form
    /// </summary>
    public class GraphicsFactory
    {
        #region Members:

        private static GraphicsFactory instance = null;
        
        private PaletteGroupView palette;
        
        private String machineXmlFile;
        //private IStateMachineHostImpl host;

        //private StateMachine machine;

        #endregion

        #region Singelton definitions:

        private GraphicsFactory(PaletteGroupView sourcePalette,
                                String           fileName)
        {
            palette = sourcePalette;
            machineXmlFile = fileName;
        }

        public static GraphicsFactory getFactory()
        {
            if (instance == null)
                // those arguments are static members of the form
                instance = new GraphicsFactory(MainForm.symbols, MainForm.fileName); 
            return instance;
        }

        #endregion

        #region Methods:

        public Initializer createInitializer(Object parameter, StatesForm owner)
        {
            Initializer initializer;

            /* need to build a root initializer: */
            if (parameter is StateMachine)
            {
                initializer = new MachineInitializer(palette, (StateMachine)parameter);
                initializer.setOwner(owner);
            }
            /* need to build a state initializer: */
            else if (parameter is State)
            {
                initializer = new SubStateInitializer(palette, (State)parameter);
                initializer.setOwner(owner);
            }
            else
                initializer = null;

            return initializer;
        }

        #endregion

    }
}
